package com.stylefeng.guns.modular.netcar.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.Tools.CodeMsg;
import com.stylefeng.guns.core.common.Tools.Result;
import com.stylefeng.guns.core.common.annotion.BussinessLog;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.core.validater.Insert;
import com.stylefeng.guns.core.validater.Update;
import com.stylefeng.guns.modular.netcar.model.LineDatePrice;
import com.stylefeng.guns.modular.netcar.service.ILineDatePriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
 * 线路特定日期加价
 *
 * @author 张亚林
 * @Date 2018-10-27 09:51
 */
@Controller
@RequestMapping(value = {"/gunsApi/auth/lineDatePrice"})
@Api(value = "线路特定日期加价操作相关api", tags = {"线路特定日期加价操作接口"})
@Slf4j(topic = "线路特定日期加价")
public class LineDatePriceController extends BaseController {
    @Autowired
    private ILineDatePriceService lineDatePriceService;
	
    /**
     * 分页获取线路特定日期加价列表
     * @param lineDatePrice
     * @param pageNum
     * @param pageSize
     * @return	
     */
    @ApiOperation(value = "分页获取线路特定日期加价列表", notes = "分页获取线路特定日期加价列表", httpMethod = "POST")
    @PostMapping(value = "/pageList", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)	
    @ResponseBody
    public Result pageList(
        @RequestBody @ApiParam(name = "lineDatePrice", value = "线路特定日期加价对象")LineDatePrice lineDatePrice,
        @ApiParam(name = "pageNum", value = "当前页数", required = true) @RequestParam(value = "pageNum", required = true) Integer pageNum,
        @ApiParam(name = "pageSize", value = "每页显示条数", required = true) @RequestParam(value = "pageSize", required = true) Integer pageSize		
        ) {
        try {
            Pager pager=new Pager();
            pager.setPageNumber(pageNum);//页码从1 开始
            pager.setPageSize(pageSize);
            pager.setObj(lineDatePrice);			
            return Result.success(lineDatePriceService.pageListLineDatePrice(pager,getToken()));
        }catch(Exception e){
            return Result.error(CodeMsg.SERVER_EXCEPTION,e.getMessage());
        }
    }
    /**
     * 获取线路特定日期加价列表
     * @param lineDatePrice    
     * @return	
     */
    @ApiOperation(value = "获取线路特定日期加价列表", notes = "获取线路特定日期加价列表", httpMethod = "POST")
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)	
    @ResponseBody
    public Result list(
        @RequestBody @ApiParam(name = "lineDatePrice", value = "线路特定日期加价对象")LineDatePrice lineDatePrice) {
        try {            
            return Result.success(lineDatePriceService.selectListLineDatePrice(lineDatePrice,getToken()));
        }catch(Exception e){
            return Result.error(CodeMsg.SERVER_EXCEPTION,e.getMessage());
        }
    }
    /**
     * 通过主键获取线路特定日期加价对象
     * @param id
     * @return
     */
    @ApiOperation(value = "通过主键获取线路特定日期加价对象", notes = "通过主键获取线路特定日期加价对象", httpMethod = "GET")
    @GetMapping(value = "/getById", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public Result getById(
            @ApiParam(name = "id", value = "主键ID", required = true) @RequestParam(value = "id", required = true) String  id
    ) {
        try {
            return Result.success(lineDatePriceService.findLineDatePriceById(id,getToken()));
        }catch(Exception e){
            return Result.error(CodeMsg.SERVER_EXCEPTION,e.getMessage());
        }
    }

    /**
     * 新增线路特定日期加价数据
     *
     * @param lineDatePrice 
     * @param result
     * @return
     */
    @ApiOperation(value = "新增线路特定日期加价数据", notes = "新增线路特定日期加价数据", httpMethod = "POST")
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)
    @BussinessLog(value = "新增线路特定日期加价数据")
    @ResponseBody
    public Result add( @Validated(value = Insert.class) @RequestBody @ApiParam(name = "lineDatePrice ", value = "线路特定日期加价对象")LineDatePrice lineDatePrice ,BindingResult result
    ) {
        if (result.hasErrors()) {
            return Result.error(CodeMsg.SERVER_EXCEPTION,"参数异常！");
        }
        try {
            lineDatePriceService.insertLineDatePrice(lineDatePrice,getToken());
            return Result.success();
        }catch(Exception e){
            return Result.error(CodeMsg.SERVER_EXCEPTION,e.getMessage());
        }
    }


    /**
     * 更新线路特定日期加价数据
     * @param lineDatePrice
     * @param result
     * @return
     */
    @ApiOperation(value = "更新线路特定日期加价数据", notes = "更新线路特定日期加价数据", httpMethod = "POST")
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)
    @BussinessLog(value = "更新线路特定日期加价数据")
    @ResponseBody
    public Result update(@Validated(value = Update.class) @RequestBody @ApiParam(name = "lineDatePrice", value = "线路特定日期加价对象")LineDatePrice lineDatePrice, BindingResult result
    ) {
        if (result.hasErrors()) {
            return Result.error(CodeMsg.SERVER_EXCEPTION,"参数异常！");
        }
        try {
            lineDatePriceService.updateLineDatePrice(lineDatePrice,getToken());
            return Result.success();
        }catch(Exception e){
            return Result.error(CodeMsg.SERVER_EXCEPTION,e.getMessage());
        }
    }
    /**
     * 删除线路特定日期加价数据
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除线路特定日期加价数据", notes = "删除线路特定日期加价数据", httpMethod = "GET")
    @GetMapping(value = "/delBatch", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @BussinessLog(value = "删除线路特定日期加价数据")
    @ResponseBody
    public Result delBatch(
            @ApiParam(name = "ids", value = "主键ID字符数组", required = true) @RequestParam(value = "ids", required = true) String ids
    ) {
        try {
            lineDatePriceService.deleteBatchLineDatePrice(ids.split(","),getToken());
            return Result.success();
        }catch(Exception e){
            return Result.error(CodeMsg.SERVER_EXCEPTION,e.getMessage());
        }
    }
	/**
     * 删除线路特定日期加价数据
     * @param lineDatePrice
     * @return
     */
    @ApiOperation(value = "删除线路特定日期加价数据", notes = "删除线路特定日期加价数据", httpMethod = "POST")
    @PostMapping(value = "/del", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)
    @BussinessLog(value = "删除线路特定日期加价数据")
    @ResponseBody
    public Result del(@RequestBody @ApiParam(name = "lineDatePrice", value = "线路特定日期加价对象")LineDatePrice lineDatePrice) {
        try {
            lineDatePriceService.deleteLineDatePrice(lineDatePrice,getToken());
            return Result.success();
        }catch(Exception e){
            return Result.error(CodeMsg.SERVER_EXCEPTION,e.getMessage());
        }
    }
    /**
     * 获取线路特定日期加价的Key-Value列表，用于html的Select数据源
     * @param lineDatePrice
     * @return
     */
    @ApiOperation(value = "获取线路特定日期加价的Key-Value列表，用于html的Select数据源", notes = "获取线路特定日期加价的Key-Value列表，用于html的Select数据源", httpMethod = "POST")
    @PostMapping(value = "/optionsList", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public Result optionsList(@RequestBody @ApiParam(name = "lineDatePrice", value = "线路特定日期加价对象")LineDatePrice lineDatePrice) {
        try {
            return Result.success(lineDatePriceService.optionsLineDatePrice(lineDatePrice,getToken()));
        }catch(Exception e){
            return Result.error(CodeMsg.SERVER_EXCEPTION,e.getMessage());
        }
    }
	private String getToken(){		
		return getHttpServletRequest().getHeader("Authorization").substring(7);
    }
}
